package com.zuoqi.easywork.userManage.controller;

import com.github.pagehelper.Page;
import com.zuoqi.common.utils.IMap;
import com.zuoqi.common.utils.PageView;
import com.zuoqi.common.utils.ReturnMapUtils;
import com.zuoqi.common.utils.SessionUtil;
import com.zuoqi.easywork.userManage.service.AttendService;
import com.zuoqi.easywork.userManage.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
public class AttendController {
    @Autowired
    private UserService userService;
    @Autowired
    private AttendService attendService;

    @RequestMapping(value = "/attendCon/toPage/attendCheckView")
    public String attendCheckView(){
        return "/module/userManage/attendCheck";
    }

    @RequestMapping(value = "/attendCon/ajax/getUserList",method = RequestMethod.POST)
    @ResponseBody
    public Map getUserList(HttpServletRequest request){
        IMap params = new IMap(request);
        Page page = PageView.startPageForTable(params, false);
        HttpSession session = request.getSession();
        String depardId = String.valueOf(session.getAttribute("loginUserDepart"));
        params.put("userDepart",depardId);
        params.put("stateScreen","true");
        List<IMap> projectList = userService.getUserListForManage(params);
        Map<String, Object> result = PageView.getResultForTable(page, projectList);
        return result;
    }
    @RequestMapping(value = "/attendCon/ajax/attendRecord",method = RequestMethod.POST)
    @ResponseBody
    public Map attendRecord(HttpServletRequest request){
        IMap param = new IMap(request);
        HttpSession session = request.getSession();
        String depardId = String.valueOf(session.getAttribute("loginUserDepart"));
        param.put("userDepart",depardId);
        int i = attendService.recordAttendByIds(param);
        if (i==1){
            return ReturnMapUtils.businessResult("0000","记录出勤成功！");
        }else return ReturnMapUtils.businessResult("9999","记录出勤失败！");
    }
}
